#ifndef LISO_ENGINE_H_
#define LISO_ENGINE_H_

#define LISTENQ		1024

#define MAX_REQ_LEN	32768	

#define LE_RECV_SUCCESS	1
#define LE_RECV_EOF		0
#define LE_RECV_FAIL	-1

#define LE_SEND_SUCCESS	0
#define LE_SEND_FAIL	-1

#include <sys/select.h>
#include "liso_buffer.h"

/* select engine */
typedef int(* http_handler)(int, client_conn_t *, void *);

typedef struct {
	int httpport;
	int sslport;
	char *logfile;
	char *lockfile;
	char *www;
	char *cgi;
	char *privatekey;
	char *cert;

	/* registed handler */
	http_handler hdl;
} select_engine_t;

/* select pool */
typedef struct {
	int maxfd;
	fd_set read_set;
	fd_set ssl_set;
	fd_set pipe_set;
	fd_set write_set;
	fd_set ready_set;
	int nready;
	client_conn_t cliconn[FD_SETSIZE];
	/* ssl global context */
	SSL_CTX *ssl_context;
} pool_t;

/* methods */
void liso_engine_create(select_engine_t *, int, int, char *, char *, char*,
		char *, char *, char *);
void liso_engine_register_http_handler(select_engine_t*, http_handler);
void liso_engine_set_pipe2sock(int, int);
int liso_engine_event_loop(select_engine_t *);
void liso_engine_shut_down(int);

#endif
